<?php

class RestController extends Zend_Rest_Controller
{

    public function init() {
        $bootstrap = $this->getInvokeArg('bootstrap');
        $options = $bootstrap->getOption('resources');
        $contextSwitch = $this->_helper->getHelper('contextSwitch');
        $contextSwitch->addActionContext('index', array('xml','json'))->initContext();
        $this->_helper->viewRenderer->setNeverRender();
        $this->view->version = "1.0";

    }

    public function headAction() {

    }

    public function indexAction() {
        if ($method = $this->getParam('method')) {
            $this->view->success = "true";
        } else {
            $this->view->success = "false";
        }

        switch ($method) {
            case 'seznam':
                $this->view->seznam = $this->zgradiSeznamProduktov();
                break;
            case 'podrobnosti':
                $id = $this->getParam('id');
                $this->view->seznam = $this->zgradiProdukt($id);
                break;
            default:
                $this->view->success = "false";
                break;
        }
    }

    public function listAction() {
        $this->_forward('index');
    }

    public function getAction() {
        $this->_forward('index');

    }

    public function newAction() {
        $this->_forward('index');
    }

    public function postAction() {
        $this->_forward('index');
    }

    public function editAction() {
        $this->_forward('index');
    }

    public function putAction() {
        $this->_forward('index');
    }

    public function deleteAction() {
        $this->_forward('index');
    }


    public function zgradiSeznamProduktov() {
        $izdelkiMapper = new Application_Model_IzdelkiMapper();
        return $izdelkiMapper->fetchAllAsArray(null);
    }

    public function zgradiProdukt($id) {
        $izdelkiMapper = new Application_Model_IzdelkiMapper();
        $where = $izdelkiMapper->getDbTable()->getAdapter()->quoteInto('idprodukt = ?', $id);
        return $izdelkiMapper->fetchAllAsArray($where);
    }
}



